<?php

namespace app\index\model;

use think\Model;

class Getyx extends Model
{
    public function item($type){
        $res = db('yuanxiao')->where('type',$type)->select();
        return $res;
    }

    public function getyx($id){
        $res = db('yuanxiao')->where('id',$id)->find();
        return $res;
    }

    //获取招生简章等 模糊查询
    public function getjz($title,$type,$limit){
        $res = db('article')->where('title', 'like' ,'%'.$title.'%'.$type.'%')->limit($limit)->select();
        return $res;
    }

    //获取推荐信息
    public function gettj($title,$type,$limit){
        $res = db('article')->where('title', 'like' ,'%'.$title.'%'.$type.'%')->limit($limit)->select();
        return $res;
    }

    //获取所有专业
    public function itemzy(){
        $res = db('zhuanye')->group('title')->select();
        return $res;
    }
    public function itemzy_one($limit){
        $res = db('zhuanye')->group('title')->limit($limit)->select();
        return $res;
    }

    //获取专业
    public function getzy($id){
        $res = db('zhuanye')->where('id',$id)->find();
        return $res;
    }

    //获取所有自考专业
    public function itemzkzy($type){
        $res = db('zikaozhuanye')->where('type',$type)->select();
        return $res;
    }
    //获取有限度的所有自考专业
    public function itemzkzy_one($type,$limit){
        $res = db('zikaozhuanye')->where('type',$type)->limit($limit)->select();
        return $res;
    }
    //获取不分类的所有自考，有限度
    public function itemzkzy_two($limit){
        $res = db('zikaozhuanye')->limit($limit)->select();
        return $res;
    }

    //获取自考专业
    public function getzkzy($id){
        $res = db('zikaozhuanye')->where('id',$id)->find();
        return $res;
    }

    //获取自考院校推荐
    public function getzkyxtj($id){
        $res = db('zikaozhuanye')->where('yuanxiao_id',$id)->select();
        return $res;
    }



    //获取某个学校开办专升本的年份
    public function yxzy_year($id){
        $res = db('zhuanye')->distinct(true)->field('year')->where('yuanxiao_id',$id)->order('year','desc')->select();
        return $res;
    } 

    //获取某个学校某年的专业
    public function yxzy_item($id){
        $year = $this -> yxzy_year($id);
        $res = array();
        foreach($year as $v){
            $data = db('zhuanye')->where(['yuanxiao_id' => $id,'year' => $v['year']])->select();
            foreach($data as $k){
                $val[] = [ 
                    'id'        =>  $k['id'],
                    'title'     =>  $k['title'],
                    'num'       =>  $k['num'],
                    'trimnum'   =>  $k['trimnum'],
                ];
            }
            $res[] = [
                'year'  =>  $v['year'],
                'data'  =>  $val
            ];
            
        }
        return $res;
    }


    //获取所有专业的年份列表
    public function yxzy_year_all(){
        $res = db('zhuanye')->distinct(true)->field('year')->order('year','desc')->select();
        return $res;
    } 

    //获取该年专业列表
    public function yxzy_year_one($year){
        $res = db('zhuanye')->where('year',$year)->order('id','desc')->select();
        return $res;
    }

    //类似专业
    public function zylike($year,$title){
        $title = mb_substr($title,0,4);
        $res = db('zhuanye')->where('year',$year)->where('title','like','%'.$title.'%')->select();
        for($i=0;$i<count($res);$i++){
            $yx = $this->getyx($res[$i]['yuanxiao_id'])['title'];
            $res[$i]['yx'] = $yx;
        }
        return $res;
    }

}